/*
 * Copyright (c) 2024-2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef COAP_ENDPOINT_CLIENT_H
#define COAP_ENDPOINT_CLIENT_H
#include <stdbool.h>
#include "coap_endpoint.h"

#ifdef __cplusplus
extern "C" {
#endif

#define COAP_CLIENT_DEFAULT_RESP_TIMEOUT (30 * 1000)

typedef void (*CoapClientRespHandler)(const CoapPacket *resp, const SocketAddr *addr, void *userData, bool timeout);

typedef struct {
    uint8_t type;
    uint8_t code;
    uint32_t opNum;
    const CoapOption *options;
    const CoapData *payload;
    CoapPacketBuildPayloadFunc payloadBuilder;
    void *payloadUserData;
    CoapClientRespHandler respHandler;
    uint32_t preSize;
} CoapClientReqParam;

int32_t CoapClientSetTokenLen(CoapEndpoint *endpoint, uint8_t tkl);

/* packetBuf应为CoapPacket的派生类，会传递到sess层作为SessMsg */
int32_t CoapClientSendReq(CoapEndpoint *endpoint, const CoapClientReqParam *param,
    const SocketAddr *addr, CoapPacket *packetBuf);

int32_t CoapClientSendCSM(CoapEndpoint *endpoint, const SocketAddr *addr,
    CoapPacket *packetBuf);

int32_t CoapClientAddDefaultRespHandler(CoapEndpoint *endpoint, CoapClientRespHandler handler);

int32_t CoapClientSetRespTimeout(CoapEndpoint *endpoint, uint32_t ms);

#ifdef __cplusplus
}
#endif

#endif /* COAP_ENDPOINT_CLIENT_H */